****************************************************************************
**  MNUTRITION GHANA- WTP PAPER ANALYSIS								 ***
**  Uses dataset created from wtp_datasetup.do    						 ***
**																		 ***
**  First Created by : Natasha Ledlie									 ***
**  Last revised by: Giordano Palloni, July 29 2020				 ***
**																		 ***
**  																	 ***
****************************************************************************

clear
clear mata
clear matrix
set maxvar 12000
set emptycells drop
set more off


// set seed
set seed 710399 /// random.org min=100000, max=999999, Oct 28 2017 9:29pm

// set do file name
loc name_do "WTP Analysis File 1"
loc name_do_short "wtp_1"

// common tasks --- -include- rather than -run- or -do- to keep locals
// note that the pathname for code has to be hardcoded here but will be in locals after this initial call
qui include "code/setup-dofile.do"

// set log file name to be the name of the sub code .do file
local name_log "`name_do'" 

// ensure no log file of the same name is currently open
cap log close "${out_log}/`name_log'"

di "${out_log}/`name_log'"

log using "${out_log}/`name_log'", replace text name(`name_do_short')


timer on 100


// call analysis dataset
use "${datain}wtp_analysis.dta", clear

***********************************
//0. Creating and cleaning variables
***********************************
	*recoding variables
	recode g1_01 g2_01 (2=0)
	label var g1_01 "Primary female owns a mobile phone"
	label var g2_01 "Primary male owns a mobile phone"
	
	*generate indicator for whether the respondent (male or female) owns a mobile
	gen resp_own_mobile = 0 if inlist(female,1) & inlist(g1_01,0) // female hh female doesn't own mobile
	replace resp_own_mobile = 0 if inlist(female,0) & inlist(g2_01,0) // male hh, male doesn't own mobile
	replace resp_own_mobile = 1 if inlist(female,1) & inlist(g1_01,1) // female hh, female owns mobile
	replace resp_own_mobile = 1 if inlist(female,0) & inlist(g2_01,1) // male hh, male owns mobile
	
	*female interacted with central region
	gen female_central = female*region_1
	label variable female_central "Female X Central region"
	
	*nut interacted with central 
	gen nut_central=nut*region_1
	label var nut_central "Agr+Nutrition script X Central region"
	
	*g any child<5
	g any_child_5=hh_ch_5>0 if hh_ch_5~=.
	label var any_child_5 "Household has a child under 5 years"
	
	*gen share of voice messages listened to for only active users
	g share_answer1_feb18=share_answer_feb18_hh if active_VFC_feb18==1
	label var share_answer1_feb18 "Share of voicemail answered, Feb 2018, for still active users"
	
	*attrition
	recode wtp_consent wtp_second_stage (2=0)
	g attrit=wtp_consent==0 | wtp_second_stage==0 if strata_1==1
	label var attrit "Did not consent or finish WTP exercise"
	
	*same sex enumerator
	g enumerator_samesex= female==1 & enumerator_sex==2
	replace enumerator_samesex= 1 if female==0 & enumerator_sex==1
	label var enumerator_samesex "Enumerator same sex as respondent"
	
***********************************
//1. Setting up locals for sample and analysis
***********************************

	*stratification
	tab b1_09

	*dropping single person strata
	drop if b1_09==2

	*analysis sample
	tab wtp_consent if strata_1==1
	tab wtp_second_stage if strata_1==1
	tab wtp_registerVFC if strata_1==1 & wtp~=.
	tab active_VFC_jun17 if strata_1==1 & wtp_consent==1 & wtp_second_stage==1 & wtp~=.
	
	gen sample=wtp_consent==1 & wtp_second_stage==1 & wtp~=.

	global sample sample //using two-person households that consented and played 2nd stage\\
	
	tab buy_5 if $sample==1
	tab buy_10 if $sample==1
	tab buy_20 if $sample==1
	tab buy_30 if $sample==1

***********************************
//2. SUMMARY STATISTICS
***********************************
	*summary stats
	local svars hh_size hh_ch_5 total_ppi z_total_asset val_total_gen3 num_crops hh_hdds hh_sim_voda /// HH level variables
		FW_educ FM_educ FW_lit FM_lit share_assets_female share_assets_male pct_correct_nut_female pct_correct_nut_male   /// male/female variables
		pct_correct_farm_female pct_correct_farm_male g1_01 g2_01 /// male/female variables
		strong_coverage cc09 /// EA level variables
	
	
	describe `svars'
	tabstat `svars', s(me n)
/**********************************************	
* Table 1 summary statistics and attrition
**********************************************/
	*attrition
	clear matrix
	foreach var of varlist attrit {
					
		mean `var'  if `var'~=. & strata_1==1 
			matrix n`var'=e(_N)
		*by script
		mean `var'  if `var'~=. & strata_1==1, over(nut) 
			matrix m1`var'=e(b)
		reg `var' nut if strata_1==1, vce(robust)
			test nut
			matrix p1_`var'=r(p)
		*standardized diff
		ttest `var' if `var'~=. & strata_1==1, by(nut)
		gen `var'1_stddiff =(r(mu_2)-r(mu_1))/sqrt(((r(sd_2)^2)+(r(sd_1)^2))/2)
		sum `var'1_stddiff if strata_1==1
			matrix std1_`var'=r(max)
		drop `var'1_stddiff
			
		*by targeting
		mean `var'  if `var'~=. & strata_1==1, over(female) 
			matrix m2`var'=e(b)
		reg `var' female if strata_1==1, vce(robust)
			test female
			matrix p2_`var'=r(p)
		*standardized diff
		ttest `var' if `var'~=. & strata_1==1, by(female)
		gen `var'2_stddiff =(r(mu_2)-r(mu_1))/sqrt(((r(sd_2)^2)+(r(sd_1)^2))/2)
		sum `var'2_stddiff  if strata_1==1
			matrix std2_`var'=r(max)
		drop `var'2_stddiff
		
		*matrix
		matrix x`var'=  n`var',m1`var', std1_`var', p1_`var', m2`var',  std2_`var', p2_`var'
		matrix rownames x`var'="`var'"
		matrix x=nullmat(x)\ x`var'
			}
			
	*sum stats
	foreach var of local svars {
					
		mean `var'  if `var'~=. & $sample==1 
			matrix n`var'=e(_N)
		*by script
		mean `var'  if `var'~=. & $sample==1, over(nut) 
			matrix m1`var'=e(b)
		reg `var' nut if $sample==1, vce(robust)
			test nut
			matrix p1_`var'=r(p)
		*standardized diff
		ttest `var' if `var'~=. & $sample==1, by(nut)
		gen `var'1_stddiff =(r(mu_2)-r(mu_1))/sqrt(((r(sd_2)^2)+(r(sd_1)^2))/2)
		sum `var'1_stddiff if $sample==1
			matrix std1_`var'=r(max)
		drop `var'1_stddiff
			
		*by targeting
		mean `var'  if `var'~=. & $sample==1, over(female) 
			matrix m2`var'=e(b)
		reg `var' female if $sample==1, vce(robust)
			test female
			matrix p2_`var'=r(p)
		*standardized diff
		ttest `var' if `var'~=. & $sample==1, by(female)
		gen `var'2_stddiff =(r(mu_2)-r(mu_1))/sqrt(((r(sd_2)^2)+(r(sd_1)^2))/2)
		sum `var'2_stddiff  if $sample==1
			matrix std2_`var'=r(max)
		drop `var'2_stddiff
		
		*matrix
		matrix z`var'=  n`var',m1`var', std1_`var', p1_`var', m2`var',  std2_`var', p2_`var'
		matrix rownames z`var'="`var'"
		matrix z=nullmat(z)\ z`var'
			}
		
		matrix z=x\z

	frmttable using "${tabout}Tables for WTP paper.doc", statmat(z) varlabels landscape sdec(0, 2) ///
	ctitles("","Script randomization", "", "", "","","Gender randomization",\ ///
	"",N,"Ag script","Ag+Nut script","Norm. diff.","P-Value","Male targeted","Female targeted","Norm diff.","P-Value" ) ///
	multic(1,2,5;1,7,4) title("{Table 1: Summary statistics, by mNutrition sub-treatment status}")  ///
	colw(50 4 6 6 4 4 6 6 4 4) titlfont(fs12 b) ctitlfont(fs10) rtitlfont(fs10) statfont(fs10) notefont(fs9)  replace ///
	note("Notes: Estimates are from the mNutrition Ghana Baseline Survey Encouraged Group, two person sample.")



***********************************
//3. REGRESSIONS 
***********************************

* control variables
	* HH level controls - not centered
	global rvars hh_size any_child_5 total_ppi z_total_asset num_crops_imp hh_sim_voda ///
	log_val_total_imp hh_hdds_imp strong_coverage cc09_q_1 cc09_q_2 cc09_q_3 
	
	* local for flags to drop, flags are indicators for imputed missing values...
	loc flag_drop_hh "num_crops_flag log_val_total_flag hh_hdds_flag"
	
/***************************************************************************
* Table 2: Willingness to pay, randomly assigned respondent gender and marketing script
***************************************************************************/
	// get mean for males without the nutrition marketing script  `: di %8.3f `female_p''
	sum wtp_winsor if inlist(female,0) & inlist(nut,0)
	loc mean_control = `r(mean)'
	loc mean_control `: di %8.3f `mean_control''
	outreg, clear
	xi:regress wtp_winsor female nut region_1  if $sample==1, vce(robust)
	xi:outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel
	
	xi: regress wtp_winsor female nut $rvars `flag_drop_hh' region_1  if $sample==1, vce(robust)
	xi:outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel drop(`flag_drop_hh')

	xi: regress wtp_winsor female nut fem_nut $rvars `flag_drop_hh' region_1 if $sample==1, vce(robust)
	xi:outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel drop(`flag_drop_hh')

	*exporting to  word
	outreg using "${tabout}Tables for WTP paper.doc", replay addtable landscape ///
	title("Table 2: Impact of framing and targeting on WTP") ///
	ctitles("Dependent variable=WTP","(1)", "(2)", "(3)") varlabel pretext("\page") ///
	coljust(l;c) colwidth(50 8 8)  basefont(fs10) titlfont(fs11 b) ///
	addrows("Control mean WTP","`mean_control'",,) ///	
	note("Robust Standard errors in parenthesis.  * p<0.1 ** p<0.05; *** p<0.01" ///
	"All specifications control for region fixed effects. Household controls included in columns 2 and 3. The Contrl mean WTP is the mean WTP among males in households that did not receive the agriculture and nutrition marketing script.")

/***************************************************************************
* Table 3: Willingness to pay, randomly assigned respondent gender and marketing script, separately by region
***************************************************************************/	
	outreg, clear
	forvalues n=0/1 {
		sum wtp_winsor if inlist(female,0) & inlist(nut,0) & inlist(region_1,`n')
		loc mean_control_`n' = `r(mean)'
		loc mean_control_`n' `: di %8.3f `mean_control_`n'''		
		xi:regress wtp_winsor female nut if $sample==1 & region_1==`n', vce(robust)
		xi:outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel
	
		xi: regress wtp_winsor female nut $rvars `flag_drop_hh' if $sample==1 & region_1==`n', vce(robust)
		xi:outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel drop(`flag_drop_hh')

		xi: regress wtp_winsor female nut fem_nut $rvars `flag_drop_hh'  if $sample==1 & region_1==`n', vce(robust)
		xi:outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel drop(`flag_drop_hh')
}
	*exporting to  word
	outreg using "${tabout}Tables for WTP paper.doc", replay addtable landscape ///
	title("Table 3: Impact of framing and targeting on WTP, by region") ///
	ctitles("", "Upper West", "","", "Central", "", ""\"Dependent variable=WTP","(1)", "(2)", "(3)", "(4)", "(5)", "(6)") varlabel pretext("\page") ///
	multicol(1,2,3;1,5,3) coljust(l;c) colwidth(50 8 8)  basefont(fs10) titlfont(fs11 b) ///	
	addrows("Control mean WTP","`mean_control_0',,,`mean_control_1'",,) ///		
	note("Robust Standard errors in parenthesis.  * p<0.1 ** p<0.05; *** p<0.01" ///
	"All specifications control for region fixed effects. Household controls included in columns 2 and 3. The Contrl mean WTP is the mean WTP among males in households that did not receive the agriculture and nutrition marketing script in the relevant region.")

/***************************************************************************
* Table 4 and C8: explaining the gender gap in demand, short results in 4 full results in C8
***************************************************************************/

	*creating variables to go into PDS lasso
		
		*individual variables without flags
		local socio WTP_age WTP_educ WTP_notmarr WTP_lit WTP_share_assets enumerator_samesex
		local knowl WTP_nut WTP_farm 
		local mobile WTP_ownmobile WTP_log_airtime WTP_heardVFC 
		local agr WTP_cropprod WTP_trust_sms_agr WTP_trust_sms_nut WTP_met_agr WTP_met_health

		*flags (indicators for missing)
		local flag_drop_all num_crops_flag log_val_total_flag hh_hdds_flag ///
			WTP_share_miss WTP_cropprod_missing WTP_trust_sms_agrmiss WTP_trust_sms_nutmiss WTP_met_agrmiss WTP_met_healthmiss
		
		tabstat $rvars `socio' `knowl' `mobile' `agr' if region_1==1, s(N)
		
		// generate controls that consist of higher order variables, interactions, and allow for interactions between the female indicator and other Xs

		local rvars_int_fem ""
		local rvars_int_nut ""
		local rvars_fac ""
		local rvars_1st ""
		local rvars_fem ""

		foreach V in $rvars `socio' `knowl' `mobile' `agr' `flag_drop_all' {
			// check if variable is binary
			count if !mi(`V') & !inlist(`V',0,1)
			// if not binary centering and interacting
			if "`r(N)'" != "0" {
				sum `V' if $sample==1 & inlist(region_1,1)
				loc var_mean = `r(mean)'
				gen `V'_cent = `V'-`var_mean'
				local x : variable label `V'
				label var `V'_cent "`x'"
				gen `V'_cent_2 = `V'_cent*`V'_cent
				loc `V'_int "c.`V'_cent#1.female"
				loc `V'_int_nut "c.`V'_cent#1.nut"
				loc `V'_2_int "c.`V'_cent_2#1.female"
				loc `V'_2_int_nut "c.`V'_cent_2#1.nut"
				loc `V'_fac "c.`V'_cent"
				
				local rvars_int_fem `"`rvars_int_fem' `V'_cent `V'_cent_2 ``V'_int' ``V'_2_int'"'
				local rvars_int_nut `"`rvars_int_nut' `V'_cent `V'_cent_2 ``V'_int_nut' ``V'_2_int_nut'"'
				local rvars_fac `"`rvars_fac' c.`V'_cent"'
				local rvars_1st `"`rvars_1st' c.`V'_cent ``V'_int'"'
				local rvars_fem `"`rvars_fem' `V'_cent `V'_cent_2"'
					
			}
			
			// if binary interacting
			if "`r(N)'" == "0" {
				loc `V'_int "1.`V'#1.female"
				loc `V'_int_nut "1.`V'#1.nut"
				loc `V'_fac "1.`V'"
				
				local rvars_int_fem `"`rvars_int_fem' ``V'_fac' ``V'_int'"' 
				local rvars_int_nut `"`rvars_int_nut' ``V'_fac' ``V'_int_nut'"'
				local rvars_fac `"`rvars_fac' 1.`V'"'
				local rvars_1st `"`rvars_1st' 1.`V' ``V'_int'"'
				local rvars_fem `"`rvars_fem' 1.`V'"'
				
			}
		} 


		// loop through all appropriately prefixed controls to generate first order interactions

		loc all_X = "`rvars_fac'"
		loc all_X_fem "`rvars_int_fem'"
		loc all_X_nut "`rvars_int_nut'"
		loc all_X_1st_fem "`rvars_1st'"
		loc all_fem "`rvars_fem' "

		loc num_X = wordcount("`all_X'")

		loc i = 1
		foreach V in `all_X' {
			loc int_main: word `i' of `all_X'
			loc next_var = `i'+1
			if `i' < `num_X' {
				forvalues j = `next_var'/`num_X' {
					loc int_oth: word `j' of `all_X'
					loc int_add "`int_main'#`int_oth'"
					loc all_X_fem `"`all_X_fem' `int_add'"'
					loc all_X_nut `"`all_X_nut' `int_add'"'
				}
			}
		loc i = `i'+1
		}

		// loop through all controls to generate quadratic terms and first order interaction terms among controls

		// list for storing all first order terms, second order terms, and first order interactions
		loc all_non_fem_int ""
		// list to identify whether a variable is binary or continuous
		loc bin_list ""
		// list to store all first order terms with appropriate prefixes for generating interactions (i. or c.)
		loc all_varlist ""
		foreach V in `socio' `knowl' `mobile' `agr' $rvars {
		// check if variable is binary
			count if !mi(`V') & !inlist(`V',0,1)
			if "`r(N)'" != "0" {
				loc bin_list `"`bin_list' cont"'
				loc all_varlist `"`all_varlist' c.`V'_cent"'
			}
			if "`r(N)'" == "0" {
				loc bin_list `"`bin_list' bin"'
				local all_varlist `"`all_varlist' 1.`V'"' 
			}	

		}

		// loop through variable list with appropriate prefixes, generate all first order interactions and second order terms (if continous)

		loc num_var = wordcount("`all_varlist'")

		loc i = 1
		foreach V in `all_varlist' {
			// store variable type
			loc vartype: word `i' of `bin_list'
			if "`vartype'" == "cont" {
				loc sec_term "`V'#`V'"
			}
			if "`vartype'" == "bin" {
				loc sec_term ""
			}
			// add first order term and second order term
			loc all_non_fem_int `"`all_non_fem_int' `V' `sec_term'"'
			// if not the last variable also generate non-duplicate interactions
			loc next_ind = `i'+1
			loc int_var ""
			if `i' != `num_var' {
				forvalues j = `next_ind'/`num_var' {
					loc other_var: word `j' of `all_varlist'
					// generate first order interaction
					loc int_var `"`int_var' `V'#`other_var'"'
				}
			}
			// add interaction terms to list
			loc all_non_fem_int `"`all_non_fem_int' `int_var'"'
			loc i = `i'+1
		}

	

	** Table 4: explaining the gender gap in the central region
		outreg, clear

		xi: regress wtp_winsor female nut $rvars `socio' `knowl' `mobile' `agr' `flag_drop_all' if $sample==1 & region_1==1, vce(robust)
		xi:outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel drop(`flag_drop_all')

		xi: pdslasso wtp_winsor female (`all_non_fem_int' nut) if $sample==1 & inlist(region_1,1), aset(nut) robust noisily lopt(center prestd)
		qui xi: outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel

		xi: pdslasso wtp_winsor female (1.nut#1.female `all_X_fem' nut) if $sample==1 & inlist(region_1,1), aset(nut) robust noisily lopt(center prestd)
		qui xi: outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel 
		

		*exporting to  word
		outreg using "${tabout}Tables for WTP paper.doc", replay addtable landscape ///
		title("Table 4: Explaining the gender gap in demand") ///
		ctitles("Dependent variable=WTP","HH and Indiv controls", "PDS Lasso", "PDS Lasso with female interaction") varlabel pretext("\page") ///
		coljust(l;c) colwidth(50 12 12 12)  basefont(fs10) titlfont(fs11 b) ///		
		addrows("Control mean WTP","`mean_control'",,) ///			
		note("Robust Standard errors in parenthesis.  * p<0.1 ** p<0.05; *** p<0.01")
		
******************Figures and Appendix table on administrative data *************
*********************************************************************************
	* local for flags to drop, flags are indicators for imputed missing values...
	loc flag_drop_hh "num_crops_flag log_val_total_flag hh_hdds_flag"
	
/************************************************************************
* Figure 1: Admin data means of registration and share of calls answered
************************************************************************/

	local active 	active_VFC_jun17 active_VFC_sep17 active_VFC_dec17 active_VFC_jan18 active_VFC_feb18 active_VFC_mar18 active_VFC_apr18
	local answer 	share_answer_dec17_hh share_answer_jan18_hh share_answer_feb18_hh share_answer_mar18_hh share_answer_apr18_hh
	
	*means
	mean `active'
	estimates store active
	mean `answer'
	estimates store answer
	
	coefplot (active, recast(connected) ///
	rename(active_VFC_jun17= "Jun17" active_VFC_sep17="Sept17" active_VFC_dec17="Dec17" active_VFC_jan18 ="Jan18" active_VFC_feb18="Feb18" active_VFC_mar18="Mar18" active_VFC_apr18 ="Apr18") mcolor(gs0) lcolor(gs0)) ///
	(answer, recast(connected) axis(1) ///
	rename(share_answer_dec17_hh="Dec17" share_answer_jan18_hh="Jan18" share_answer_feb18_hh ="Feb18" share_answer_mar18_hh="Mar18" share_answer_apr18_hh="Apr18" ) mcolor(gs6) lcolor(gs6) lpattern(dash)), ///
	vertical noci nooffsets  ytitle(Share) xtitle(Month) legend(order(1 "Farmers on the VFC service" 2 "Voice calls answered")) ///
	graphregion(color(white)) plotregion(color(white))
	graph export "${figout}figure1.eps", replace fontface(times)	
	graph export "${figout}figure1.png", replace
	png2rtf using "${figout}figure1.doc", graph("${figout}figure1.png") replace
	
/************************************************************************	
** Figure 7 and Appendix table C3 and C4: WTP and share of farmers on VFC service? 
************************************************************************/

	
	*coefficients of activation on wtp
	outreg, clear
	foreach month in jun17 sep17 dec17 jan18 feb18 mar18 apr18 {
		regress active_VFC_`month' wtp_winsor female nut $rvars `flag_drop_hh' region_1 if $sample==1  , vce(robust)
		outreg, merge se starlevels(10 5 1)  bdec(2) sfmt(fc) varlabel drop($rvars `flag_drop_hh')
		estimates store active_`month'
	}
	
	*Table C3
	outreg using "${tabout}Tables for WTP paper.doc", replay addtable landscape ///
	title("Appendix Table C3: Activation rates and WTP") ctitles("","Jun 17", "Sept 17", "Dec 17", "Jan 18", "Feb 18", "Mar 18","Apr 18") ///
	varlabel pretext("\page") coljust(l;c) colwidth(40 9 9 9 9 9 9 9 9)  basefont(fs10) titlfont(fs11 b) ///			
	note("Robust Standard errors in parenthesis.  * p<0.1 ** p<0.05; *** p<0.01" ///
	"All specifications control for region fixed effects, household and EA-level controls.")


	*coefficients of activation on wtp, by region
	outreg, clear
	forvalues n=0/1{
	foreach month in jun17 sep17 dec17 jan18 feb18 mar18 apr18 {
		regress active_VFC_`month' wtp_winsor female nut $rvars `flag_drop_hh' if $sample==1 & region_1==`n' , vce(robust)
		outreg, merge se starlevels(10 5 1)  bdec(2) sfmt(fc) varlabel drop($rvars `flag_drop_hh')
		estimates store active_`month'_`n'
	}
	}

	*Table C4
	outreg using "${tabout}Tables for WTP paper.doc", replay addtable landscape title("Appendix Table C4: Activation rates and WTP, by region") ///
 	multicol(1,2,7;1,9,7) ctitles(" ","Upper West", "", "", "", "","","","Central", "", "", "","","",""\ ///
	"","Jun 17", "Sept 17", "Dec 17", "Jan 18", "Feb 18", "Mar 18","Apr 18", "Jun 17", "Sept 17", "Dec 17", "Jan 18", "Feb 18", "Mar 18","Apr 18") ///
	varlabel pretext("\page") coljust(l;c) colwidth(40 9 9 9 9 9 9 9 9 9 9 9 9)  basefont(fs10) titlfont(fs11 b) ///			
	note("Robust Standard errors in parenthesis.  * p<0.1 ** p<0.05; *** p<0.01" ///
	"All specifications control for household and EA-level controls.")

	*Figure 7. Service Participation and WTP
	coefplot active_jun17 active_jun17_0 active_jun17_1  || active_sep17 active_sep17_0 active_sep17_1 || ///
			active_dec17 active_dec17_0 active_dec17_1 || active_jan18 active_jan18_0 active_jan18_1 || ///
			active_feb18 active_feb18_0 active_feb18_1 || active_mar18 active_mar18_0 active_mar18_1 || active_apr18 active_apr18_0 active_apr18_1,	///
		p1(mcolor(gs0)) p2(mcolor(gs6)) p3(mcolor(gs12)) ///	
		keep(wtp_winsor) yline(0, lcolor(gs0) lpattern(dash)) vertical bycoefs ciopts(recast(rbar) barwidt(0.1) fcolor(white) lcolor(gs9)) levels(90) ///
		ytitle(Coefficient estimate) ylabel(-.06(.02).06) p2(pstyle(p2)) p3(pstyle(p3)) ///
		xlabel(1 "Jun '17" 2 "Sept '17" 3 "Dec '17" 4 "Jan '18" 5 "Feb '18" 6 "Mar '18" 7 "Apr '18")   ///
		legend(order(1 "90% CI" 2 "Point estimate, Full sample" 4 "Point estimate, Upper West" 6 "Point estimate, Central")) ///
		graphregion(color(white)) plotregion(color(white))
	graph export "${figout}figure7.eps", replace fontface(times)
	graph export "${figout}figure7.png", replace
	png2rtf using "${figout}figure7.doc", graph("${figout}figure7.png") replace
	
/************************************************************************	
** Figure 8 and Appendix table C5 and C6: WTP and the share of unique VFC voicemails listened to 
************************************************************************/	

	*Esoko voicemail,
	outreg, clear
	foreach month in dec17 jan18 feb18 mar18 apr18 {
		regress share_answer_`month'_hh wtp_winsor female nut $rvars `flag_drop_hh' region_1 if $sample==1 , vce(robust)
		outreg, merge se starlevels(10 5 1)  bdec(2) sfmt(fc) varlabel drop($rvars `flag_drop_hh')
		estimates store voice_`month'
	}

	*Table C5
	outreg using "${tabout}Tables for WTP paper.doc", replay addtable landscape ///
	title("Appendix Table C5: Voicemail usage and WTP") varlabel pretext("\page")	 ///
	ctitles("", "Dec 17", "Jan 18", "Feb 18", "Mar 18","Apr 18" ) ///
	coljust(l;c) colwidth(40 9 9 9 9 9 9)  basefont(fs10) titlfont(fs11 b) ///			
	note("Robust Standard errors in parenthesis.  * p<0.1 ** p<0.05; *** p<0.01" ///
	"All specifications control for region fixed effects, household and EA-level controls.")

	
	*Esoko voicemail, by region
	outreg, clear
	forvalues n=0/1{
	foreach month in dec17 jan18 feb18 mar18 apr18 {
		regress share_answer_`month'_hh wtp_winsor female nut $rvars `flag_drop_hh' if $sample==1 & region_1==`n' , vce(robust)
		outreg, merge se starlevels(10 5 1)  bdec(2) sfmt(fc) varlabel drop($rvars `flag_drop_hh')
		estimates store voice_`month'_`n'
	}
	}
	
	*Table C6
	outreg using "${tabout}Tables for WTP paper.doc", replay addtable landscape ///
	title("Appendix Table C6: Voicemail usage and WTP, by region") 	multicol(1,2,5;1,7,5) ///
	ctitles(" ","Upper West", "", "","","","Central", "", "", "",""\ ///
	"", "Dec 17", "Jan 18", "Feb 18", "Mar 18","Apr 18" , "Dec 17", "Jan 18", "Feb 18", "Mar 18","Apr 18") ///
	varlabel pretext("\page") coljust(l;c) colwidth(40 9 9 9 9 9 9 9 9 9 9 9 9)  basefont(fs10) titlfont(fs11 b) ///			
	note("Robust Standard errors in parenthesis.  * p<0.1 ** p<0.05; *** p<0.01" ///
	"All specifications control for household and EA-level controls.")

	*Figure 8. Share of unique voicemails listened to and WTP
	coefplot  voice_dec17 voice_dec17_0	 voice_dec17_1	|| voice_jan18 voice_jan18_0 voice_jan18_1 || ///
		voice_feb18 voice_feb18_0 voice_feb18_1 || voice_mar18 voice_mar18_0 voice_mar18_1 || voice_apr18 voice_apr18_0 voice_apr18_1,  ///
		p1(mcolor(gs0)) p2(mcolor(gs6)) p3(mcolor(gs12)) ///
		keep(wtp_winsor) yline(0, lcolor(gs0) lpattern(dash)) vertical bycoefs ciopts(recast(rbar) barwidt(0.1) fcolor(white) lcolor(gs9)) levels(90) ///
		ytitle(Coefficient estimate) ylabel(-.06(.02).06)   ///
		xlabel(1 "Dec '17" 2 "Jan '18" 3 "Feb '18" 4 "Mar '18" 5 "Apr '18")  p2(pstyle(p2)) p2(pstyle(p3)) ///
		legend(order(1 "90% CI" 2 "Point estimate, Full sample" 4 "Point estimate, Upper West" 6 "Point estimate, Central")) ///
		graphregion(color(white)) plotregion(color(white))
	graph export "${figout}figure8.eps", replace fontface(times)
	graph export "${figout}figure8.png", replace
	png2rtf using "${figout}figure8.doc", graph("${figout}figure8.png") replace
	

*************************************
* 5. Robustness tables
*************************************
*************************************
* Tables C1 and C2. Summary Stats by Region
*************************************
	
	*attrition
	forvalues n=0/1 {
	clear matrix
	foreach var of varlist attrit {
					
		mean `var'  			if `var'~=. & strata_1==1 & region_1==`n' 
			matrix n`var'=e(_N)
		*by script
		mean `var'  			if `var'~=. & strata_1==1 & region_1==`n' , over(nut) 
			matrix m1`var'=e(b)
		reg `var' nut 			if strata_1==1 & region_1==`n' , vce(robust)
			test nut
			matrix p1_`var'=r(p)
		*standardized diff
		ttest `var' 			if `var'~=. & strata_1==1 & region_1==`n' , by(nut)
		gen `var'1_stddiff =(r(mu_2)-r(mu_1))/sqrt(((r(sd_2)^2)+(r(sd_1)^2))/2)
		sum `var'1_stddiff 		if strata_1==1 & region_1==`n' 
			matrix std1_`var'=r(max)
		drop `var'1_stddiff
			
		*by targeting
		mean `var'  			if `var'~=. & strata_1==1 & region_1==`n' , over(female) 
			matrix m2`var'=e(b)
		reg `var' female 		if strata_1==1 & region_1==`n' , vce(robust)
			test female
			matrix p2_`var'=r(p)
		*standardized diff
		ttest `var' 			if `var'~=. & strata_1==1 & region_1==`n' , by(female)
		gen `var'2_stddiff =(r(mu_2)-r(mu_1))/sqrt(((r(sd_2)^2)+(r(sd_1)^2))/2)
		sum `var'2_stddiff  	if strata_1==1 & region_1==`n' 
			matrix std2_`var'=r(max)
		drop `var'2_stddiff
		
		*matrix
		matrix x`var'=  n`var',m1`var', std1_`var', p1_`var', m2`var',  std2_`var', p2_`var'
		matrix rownames x`var'="`var'"
		matrix x=nullmat(x)\ x`var'
			}
			
	*sum stats
	foreach var of local svars {
					
		mean `var'  			if `var'~=. & $sample==1  & region_1==`n' 
			matrix n`var'=e(_N)
		*by script
		mean `var'  			if `var'~=. & $sample==1 & region_1==`n' , over(nut) 
			matrix m1`var'=e(b)
		reg `var' nut 			if $sample==1 & region_1==`n' , vce(robust)
			test nut
			matrix p1_`var'=r(p)
		*standardized diff
		ttest `var' 			if `var'~=. & $sample==1 & region_1==`n' , by(nut)
		gen `var'1_stddiff =(r(mu_2)-r(mu_1))/sqrt(((r(sd_2)^2)+(r(sd_1)^2))/2)
		sum `var'1_stddiff 		if $sample==1 & region_1==`n' 
			matrix std1_`var'=r(max)
		drop `var'1_stddiff
			
		*by targeting
		mean `var'  			if `var'~=. & $sample==1 & region_1==`n' , over(female) 
			matrix m2`var'=e(b)
		reg `var' female 		if $sample==1 & region_1==`n' , vce(robust)
			test female
			matrix p2_`var'=r(p)
		*standardized diff
		ttest `var' 			if `var'~=. & $sample==1 & region_1==`n' , by(female)
		gen `var'2_stddiff =(r(mu_2)-r(mu_1))/sqrt(((r(sd_2)^2)+(r(sd_1)^2))/2)
		sum `var'2_stddiff  	if $sample==1 & region_1==`n' 
			matrix std2_`var'=r(max)
		drop `var'2_stddiff
		
		*matrix
		matrix z`var'=  n`var',m1`var', std1_`var', p1_`var', m2`var',  std2_`var', p2_`var'
		matrix rownames z`var'="`var'"
		matrix z=nullmat(z)\ z`var'
			}
		
		matrix z=x\z

	frmttable using "${tabout}Tables for WTP paper.doc", statmat(z) varlabels landscape sdec(0, 2)  pretext("\page") ///
	ctitles("","Script randomization", "", "", "","","Gender randomization",\ ///
	"",N,"Ag script","Ag+Nut script","Norm. diff.","P-Value","Male targeted","Female targeted","Norm diff.","P-Value" ) ///
	multic(1,2,5;1,7,4) title("{Appendix Tables C1 and C2: Summary statistics, by mNutrition sub-treatment status,`n'}")  ///
	colw(50 4 6 6 4 4 6 6 4 4) titlfont(fs12 b) ctitlfont(fs10) rtitlfont(fs10) statfont(fs10) notefont(fs9)  addtable ///
	note("Notes: Estimates are from the mNutrition Ghana Baseline Survey Encouraged Group, two person sample.")
	}

*************************************
* Robustness of Main Results to Winsorizing at the 99th percentile (not in current draft)
*************************************	

* Table 2, by region
	outreg, clear
	xi:regress wtp_winsor2 female nut region_1  if $sample==1 , vce(robust)
	xi:outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel 
	
	xi: regress wtp_winsor2 female nut $rvars `flag_drop_hh' region_1  if $sample==1 , vce(robust)
	xi:outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel drop(`flag_drop_hh')

	xi: regress wtp_winsor2 female nut fem_nut $rvars `flag_drop_hh' region_1  if $sample==1, vce(robust)
	xi:outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel drop(`flag_drop_hh')
	
	*exporting to  word
	outreg using "${tabout}Tables for WTP paper.doc", replay addtable landscape ///
	title("Table X: Robust impact of framing and targeting on WTP, winsorized at the top 1 percent") ///
	ctitles("Dependent variable=WTP","(1)", "(2)", "(3)") varlabel pretext("\page") ///
	coljust(l;c) colwidth(50 8 8)  basefont(fs10) titlfont(fs11 b) ///			
	note("Robust Standard errors in parenthesis.  * p<0.1 ** p<0.05; *** p<0.01" ///
	"All specifications control for region fixed effects. Household controls included in columns 2 and 3.")

	* Table 3 by region
	outreg, clear
	forvalues n=0/1 {
		xi:regress wtp_winsor2 female nut if $sample==1 & region_1==`n', vce(robust)
		xi:outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel
	
		xi: regress wtp_winsor2 female nut $rvars `flag_drop_hh' if $sample==1 & region_1==`n', vce(robust)
		xi:outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel drop(`flag_drop_hh')

		xi: regress wtp_winsor2 female nut fem_nut $rvars `flag_drop_hh'  if $sample==1 & region_1==`n', vce(robust)
		xi:outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel drop(`flag_drop_hh')
}
	*exporting to  word
	outreg using "${tabout}Tables for WTP paper.doc", replay addtable landscape ///
	title("Table X: Robust impact of framing and targeting on WTP, by region, wonsorized at the top 1 percent") ///
	ctitles("", "Upper West", "","", "Central", "", ""\"Dependent variable=WTP","(1)", "(2)", "(3)", "(4)", "(5)", "(6)") varlabel pretext("\page") ///
	multicol(1,2,3;1,5,3) coljust(l;c) colwidth(50 8 8)  basefont(fs10) titlfont(fs11 b) ///			
	note("Robust Standard errors in parenthesis.  * p<0.1 ** p<0.05; *** p<0.01" ///
	"All specifications control for region fixed effects. Household controls included in columns 2 and 3.")


*************************************
* Table C7: Showing regression results separately by whether the respondent owns or does not own a mobile phone
*************************************	

	outreg, clear
	xi:regress wtp_winsor female nut region_1 $rvars `flag_drop_hh'  if $sample==1, vce(robust)
	xi:outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel keep(female nut region_1 _cons)
	
	xi: regress wtp_winsor female nut region_1 $rvars `flag_drop_hh' if $sample==1 & inlist(resp_own_mobile,1), vce(robust)
	xi:outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel  keep(female nut region_1 _cons)
	
	xi: regress wtp_winsor female nut region_1 $rvars `flag_drop_hh' if $sample==1 & inlist(resp_own_mobile,1)
	estimates store est_1
	
	xi: regress wtp_winsor female nut region_1 $rvars `flag_drop_hh' if $sample==1 & inlist(resp_own_mobile,0), vce(robust)
	xi:outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel  keep(female nut region_1 _cons)
	
	xi: regress wtp_winsor female nut region_1 $rvars `flag_drop_hh' if $sample==1 & inlist(resp_own_mobile,0)
	estimates store est_0
	
	suest est_1 est_0, vce(robust)
	// get p-value for test of no difference in female coefficient (chi-squared test)
	test [est_1_mean=est_0_mean]:female
	loc female_p = `r(p)'
	loc female_p `: di %8.3f `female_p''
	// get p-value for test of no difference in nutrition coefficient 
	test [est_1_mean=est_0_mean]:nut
	loc nut_p = `r(p)'
	loc nut_p `: di %8.3f `nut_p''
	
	*exporting to  word
	outreg using "${tabout}Tables for WTP paper.doc", replay addtable landscape ///
	title("Table C7: Impact of framing and targeting on WTP by mobile phone ownership") ///
	ctitles("Dependent variable=WTP","(1)", "(2)", "(3)") varlabel pretext("\page") ///
	coljust(l;c) colwidth(50 8 8)  basefont(fs10) titlfont(fs11 b) ///
	addrows("P-value: No difference in female coeff between (2) and (3)","`female_p'"\"P-value: No difference in agriculture and nutrition coeff between (2) and (3)","`nut_p'") ///
	note("Table displays estimates from Ordinary Least Squares regressions of " ///
	"willingness-to-pay (WTP) on whether households were assigned to the female targeted treatment arm and whether they were assigned to the agriculture + nutrition " ///
	"marketing script. All specifications control for region fixed effects, household size, whether the household has a child under age 5, the progress out of " ///
	"poverty index (PPI) score, the total household asset index, the number of crops cultivated by the household, whether the household owned a Vodafone SIM card, " ///
	"the log of the total value of agricultural production, the household dietary diversity score, whether the enumeration area (EA) had strong Vodafone network " ///
	"coverage, and indicators for the quartile the household belongs to in terms of distance to the nearest market. Column 1 includes the full analysis sample, " ///
	"Column 2 is restricted to households " ///
	"where the respondent (male or female) owns their own mobile phone, and Column 3 is restricted to households where the respondent does not own their own mobile " ///
	"phone. The p-values shown at the base of the table correspond to Chi-squared tests of whether there is no difference in the coefficient on whether households " ///
	"were randomly assigned to the female targeted group or whether households were randomly assigned to the agriculture and nutrition script between households " ///
	"where the respondent owned their own mobile phone and households where they did not. Robust Standard errors in parentheses.  * p<0.1 ** p<0.05; *** p<0.01")


*************************************
* Table C9: Showing regression results of wtp on early/late interview
*************************************	

	outreg, clear
	xi:regress wtp_winsor interview_early if $sample==1, vce(robust)
	xi:outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel
	
	xi: regress wtp_winsor interview_early female nut region_1 $rvars `flag_drop_hh' if $sample==1, vce(robust)
	xi:outreg, merge se starlevels(10 5 1)  bdec(3) sfmt(fc) varlabel drop(`flag_drop_hh')
	
	*exporting to  word
	outreg using "${tabout}Tables for WTP paper.doc", replay addtable landscape ///
	title("Table C9: Impact of an early interview on WTP") ///
	ctitles("Dependent variable=WTP","(1)", "(2)") varlabel pretext("\page") ///
	coljust(l;c) colwidth(50 8 8)  basefont(fs10) titlfont(fs11 b) ///
	note("Table displays Ordinary Least Squares estimates of the association between whether individuals were interviewed " ///
	"in the first (early) half of household in their enumeration area (EA) and willingness-to-pay (WTP). Column 1 includes no controls. " ///
	"Column 2 adds controls for region fixed effects, household size, whether the household has a child under age 5, the progress out of " ///
	"poverty index (PPI) score, the total household asset index, the number of crops cultivated by the household, whether the household owned a Vodafone SIM card, " ///
	"the log of the total value of agricultural production, the household dietary diversity score, whether the enumeration area (EA) had strong Vodafone network " ///
	"coverage, and indicators for the quartile the household belongs to in terms of distance to the nearest market. " ///
	"Robust Standard errors in parentheses.  * p<0.1 ** p<0.05; *** p<0.01")

/****************************************************
* END OF WTP ANALYSIS FILE 1 CODE
****************************************************/

// close log file

log close `name_do_short'
	